<?php

class Plugin
{
	private static $_list = array();
	private static $_site = array();
	
	public static function register($name, $path = NULL)
	{
		if ($path !== NULL)
		{
			self::$_site[strtolower($path)][] = $name;
		}
		else
		{
			self::$_list[] = $name;
		}
	}
	
	public static function pre()
	{
		$a = array();
		$site = strtolower($_SERVER['REDIRECT_URL']);
		
		foreach (self::$_list as $file)
		{
			$a[] = 'Plugin/' . $file . '/pre.php';
		}
		
		if (
		    isset(self::$_site[$site])
		    && is_array(self::$_site[$site])
		)
		{
			foreach (self::$_site[$site] as $file)
			{
				$a[] = 'Plugin/' . $file . '/pre.php';
			}
		}
		return $a;
	}
	
	public static function post()
	{
		$a = array();
		$site = strtolower($_SERVER['REDIRECT_URL']);
		
		foreach (self::$_list as $file)
		{
			$a[] = 'Plugin/' . $file . '/post.php';
		}
		
		if (
		    isset(self::$_site[$site])
		    && is_array(self::$_site[$site])
		)
		{
			foreach (self::$_site[$site] as $file)
			{
				$a[] = 'Plugin/' . $file . '/post.php';
			}
		}
		return $a;
	}
}